﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="IDM.Web._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>IDM - Proof of concept</title>        
</head>
<body>
    <form id="form1" runat="server">
    
    <ext:ResourceManager runat="server">
    <Listeners>
		<DocumentReady Handler="#{Structure}.getSelectionModel().select(#{Structure}.getRootNode().firstChild);" Delay="250" />
    </Listeners>
    </ext:ResourceManager>
    
    <ext:Store runat="server" ID="GridStore" 
		OnRefreshData="StoreReload">
    <Reader>
		<ext:JsonReader IDProperty="ID">
		<Fields>
			<ext:RecordField Name="ID" Type="Int" />
			<ext:RecordField Name="Name" />
			<ext:RecordField Name="Changed" Type="Date" AllowBlank="true" />
		</Fields>		
		</ext:JsonReader>
    </Reader>
    
    </ext:Store>
    
    <ext:Viewport runat="server" Layout="Border">    
    <Content>
    
		<ext:Panel runat="server"
			Region="North"
			Height="25">
		<TopBar>
			<ext:Toolbar runat="server">
			<Items>
				<ext:Label runat="server"
					Icon="Application"
					IconAlign="Left"
					Text="SIO-MDM - Proof of concept">
				</ext:Label>				
				<ext:ToolbarFill runat="server" />
				<ext:Button runat="server" ID="UserButton"
					Text=""
					Icon="User">
				</ext:Button>
				<ext:Button runat="server"
					ID="LogoutBtn"
					Icon="LockStop"
					Text="Logout">
				<DirectEvents>
					<Click OnEvent="Logout">
						<EventMask ShowMask="true" />
					</Click>
				</DirectEvents>
				</ext:Button>
			</Items>
			</ext:Toolbar>
		</TopBar>
		</ext:Panel>
			
    
    	<ext:TreePanel runat="server" 
    		Region="West"
    		Width="200"
    		RootVisible="false"
    		Collapsible="true"
    		UseArrows="true"
    		CollapseMode="Mini"
    		Split="true"
    		Header="false"
    		ID="Structure">
    	<Root>
			<ext:TreeNode>
			<Nodes>
				<ext:TreeNode NodeID="UsersNode" Text="Users" Icon="User" />				
				<ext:AsyncTreeNode NodeID="RolesNode" Text="Roles" Icon="Group" />
				<ext:AsyncTreeNode NodeID="TokensNode" Text="Tokens" Icon="Key" />				
			</Nodes>
			</ext:TreeNode>
		</Root>		
		<Loader>
			<ext:PageTreeLoader OnNodeLoad="LoadNode">			
			<BaseParams>
				<ext:Parameter Name="parent" Mode="Raw" Value="node.attributes.ctx" />
			</BaseParams>
			</ext:PageTreeLoader>
		</Loader>
		<SelectionModel>
			<ext:DefaultSelectionModel runat="server" ID="StructureSelectionModel">
				<DirectEvents>
					<SelectionChange OnEvent="NodeSelected">
					<ExtraParams>
						<ext:Parameter Name="parent" Mode="Raw" Value="node.attributes.ctx" />						
						<ext:Parameter Name="node" Mode="Raw" Value="node.id" />
					</ExtraParams>
					<EventMask ShowMask="true" CustomTarget="ObjectsList" />
					</SelectionChange>
				</DirectEvents>
			</ext:DefaultSelectionModel>
		</SelectionModel>
		</ext:TreePanel>
    
    	<mdm:GridPanel runat="server" Region="Center"
    		ID="ObjectsList"
			StoreID="GridStore"
			AutoExpandColumn="Name">
			            <Plugins>
                <ext:RowEditor ID="RowEditor1" runat="server" SaveText="Shrani" CancelText="Prekliči" ><DirectEvents>
                <AfterEdit OnEvent="ImeFunkcije" ><ExtraParams>
                   <ext:Parameter Name="Id" Value="r.data.ID" Mode="Raw"></ext:Parameter>
                   <ext:Parameter Name="Name" Value="r.data.Name" Mode="Raw"></ext:Parameter>
                </ExtraParams></AfterEdit>
                </DirectEvents></ext:RowEditor>
            </Plugins>
			<View>
			<ext:GridView runat="server" MarkDirty="true"></ext:GridView>
			</View>
		<ColumnModel>
		<Columns>
			<ext:Column ColumnID="ID" Hidden="true" Hideable="false"></ext:Column>
			<ext:Column Header="Name" ColumnID="Name" DataIndex="Name">
			<Editor ><ext:TextField runat="server" ID="Polje1" AllowBlank="false"></ext:TextField></Editor>
			</ext:Column>
			<ext:Column Header="Changed" ColumnID="Changed" Width="200"></ext:Column>
		</Columns>
		</ColumnModel>
		<SelectionModel>
			<ext:RowSelectionModel runat="server" SingleSelect="true"></ext:RowSelectionModel>
		</SelectionModel>
		<TopBar>
			<ext:Toolbar runat="server">
			<Items>
				<ext:Button runat="server" ID="Add"
					Text="Add"
					Icon="Add">
				<Listeners>
					<Click Handler="showDialog(#{EditDialog});" />
				</Listeners>
				</ext:Button>
				<mdm:Button runat="server" ID="Edit"
					Text="Edit"
					Icon="Pencil"
					ConfirmAction="true"
					CofirmText="Editiram?">
				<Listeners>
					<Click Handler="showDialog(#{EditDialog}, {id: #{ObjectsList}.getSelectionModel().getSelected().data.ID});" />
				</Listeners>
				</mdm:Button>
				<mdm:Button runat="server" ID="Remove"
					Text="Remove"
					Icon="Delete">
				<DirectEvents>
					<Click OnEvent="DeleteItem" After="#{GridStore}.reload();">
					<Confirmation ConfirmRequest="true" Message="Delete items?" />
					<ExtraParams>
						<ext:Parameter Name="node" Mode="Raw" Value="#{Structure}.getSelectionModel().getSelectedNode().id" />
						<ext:Parameter Name="selected" Mode="Raw" Value="Ext.encode(#{ObjectsList}.getRowsValues({selectedOnly:true}))" />
					</ExtraParams>
					</Click>
				</DirectEvents>							
				</mdm:Button>
			</Items>
			</ext:Toolbar>
		</TopBar>
		</mdm:GridPanel>
    </Content>
    </ext:Viewport>
    
    <mdm:Dialog runat="server" ID="EditDialog"
		Width="500"
		Height="400"
		Url="AddUser.aspx"
		DialogButtons="SaveClose">
	<Listeners>		
		<Hide Handler="#{GridStore}.reload();" />
	</Listeners>
	</mdm:Dialog>        
    
    </form>
</body>
</html>
